package com.sniff.atp.service.login;

import com.sniff.atp.dto.SystemLoginDTO;
import com.sniff.atp.enums.api.CustomerAPI;
import com.sniff.atp.utils.HttpClientUtil;
import com.sniff.atp.utils.JsonUtil;
import org.springframework.stereotype.Service;

import java.util.HashMap;

/**
 * @BelongsProject: sniff-atp
 * @BelongsPackage: com.sniff.atp.service.login
 * @Author: zxy
 * @CreateTime: 2022-10-28 17:08
 * @Description: 平台端登录
 * @Version: 1.0
 */
@Service
public class SystemLoginService {

    public SystemLoginDTO login(String username, String password) {
        HashMap<String, Object> params = new HashMap<>();
        params.put("username", username);
        params.put("password", password);

        String result = new HttpClientUtil().doPost(CustomerAPI.SYSTEM_LOGIN.getApi(), params);
        SystemLoginDTO systemLoginDTO = new SystemLoginDTO();
        systemLoginDTO.setToken(JsonUtil.extractString(result, "data.token"));

        return systemLoginDTO;
    }
}
